package org.csu.agrisupply.api.controller.front;

import org.csu.agrisupply.api.common.CommonResponse;
import org.csu.agrisupply.api.entity.FormOffer;
import org.csu.agrisupply.api.entity.FormOrder;
import org.csu.agrisupply.api.service.FormOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/formOrders/")
public class FormOrderController {
    @Autowired
    private FormOrderService formOrderService;

    @GetMapping("")
    @ResponseBody
    //得到所有订货订单
    public CommonResponse<List<FormOrder>> getFormOrderList(){
        return formOrderService.getFormOrderList();
    };
    @GetMapping("{orderId}")
    @ResponseBody
    //得到单个订货订单
    public CommonResponse<FormOrder> getFormOrder(@PathVariable("orderId") String orderId){
        return formOrderService.getFormOrder(orderId);
    };
    @PostMapping("forms/{formId}/users/{userId}")
    @ResponseBody
    //生成订单
    public CommonResponse<FormOrder> createFormOrder(@PathVariable("formId") String formId,
                                                     @PathVariable("userId") String userId){
        return formOrderService.createFormOrder(formId,userId);
    };
}
